package kr.saeildamil.androidstudy.ch12;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewTestEx extends Activity {
	String[] arr;
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_listviewtest);
		arr = getResources().getStringArray(R.array.country);

		// 스트링스에 목록을 만든다음 어댑터만 생성하면 끝
		ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter
				.createFromResource(this, R.array.country,
					  android.R.layout.simple_list_item_1); //리스트목록 
	
		ListView list = (ListView) findViewById(R.id.ch12_listviewtest_list);
		list.setAdapter(arrayAdapter);

		list.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				String str = "선택된 멘붕의 나라는 " + arr[position] + "입니다";
				Toast.makeText(ListViewTestEx.this, str, Toast.LENGTH_LONG).show();
			}
		});

	}

}
